/********************************************
*
*
*
*  test_list.c
*
*
********************************************/


#ifdef __cplusplus
 #if __cplusplus
  extern "C"{
 #endif
#endif /* __cplusplus */


#include "test_suite.h"
#include "d_list.h"
#include <stdlib.h>

typedef struct stTestList {
	UINT32 uli;
	VOID * pData;
	DMS_LIST_NODE stListNode;
}S_TESTLIST;

S_TESTLIST stTestListHead;

UINT32 TEST_Add_00()
{
	UINT32 i;
	S_TESTLIST * pstTestListNode = NULL;
	DMS_LIST_NODE * pstItem;
	DMS_LIST_NODE * pstHead;

	pstHead = &(stTestListHead.stListNode);
	DMS_LIST_INIT(pstHead);

	for(i = 0 ; i < 1000 ; i++)
	{
		pstTestListNode = (S_TESTLIST *)malloc(sizeof(S_TESTLIST));
		CU_UNEQUAL(NULL , pstTestListNode);

		pstTestListNode->uli = i ;
		pstTestListNode->pData = (VOID *)pstTestListNode;

		pstItem = &pstTestListNode->stListNode;
		DMS_LIST_ADD(pstItem, pstHead);
	}

	i = 999;

	DMS_LIST_TRAVERSAL(pstItem, pstHead)
	{
		pstTestListNode = DMS_LIST_OFFSET(pstItem, S_TESTLIST, stListNode);

		CU_EQUAL(pstTestListNode->pData , pstTestListNode);

		CU_EQUAL(pstTestListNode->uli , i);

		i--;
	}

	CU_EQUAL(NULL_LONG , i);

	DMS_LIST_TRAVERSAL(pstItem, pstHead)
	{
		pstTestListNode = DMS_LIST_OFFSET(pstItem, S_TESTLIST, stListNode);
		DMS_LIST_REMOVE(&pstTestListNode->stListNode);
		free(pstTestListNode);
	}

    return DMS_OK;
}

UINT32 TEST_Add_01()
{

    return DMS_OK;
}

UINT32 TEST_Add_02()
{

    return DMS_OK;
}

UINT32 TEST_Add_03()
{

    return DMS_OK;
}



VOID TEST_Add()
{
    CU_EQUAL(TEST_Add_00(),DMS_OK);
    CU_EQUAL(TEST_Add_01(),DMS_OK);
    CU_EQUAL(TEST_Add_02(),DMS_OK);
    CU_EQUAL(TEST_Add_03(),DMS_OK);
}


VOID TEST_suite_list(VOID)
{
    CU_pSuite suite;
    suite = CU_add_suite(__FUNCTION__, NULL, NULL);
    CU_ADD_TEST(suite, TEST_Add);
}

#ifdef __cplusplus
 #if __cplusplus
  }
 #endif
#endif /* __cplusplus */
